import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { ILike, Repository } from 'typeorm';
import { Map } from './entities/map.entity';

@Injectable()
export class MapService {
  constructor(
    @InjectRepository(Map)
    private readonly mapRepository: Repository<Map>,
  ) {}

  async findAll(provinceKeys) {
    const res = await this.mapRepository.find({
      where: { province: ILike(`%${provinceKeys}%`) },
    });
    const children = [];

    res.forEach((item) => {
      children.push({
        label: item.city,
        value: item.city,
      });
    });

    return {
      code: 900,
      result: [
        {
          label: provinceKeys,
          value: provinceKeys,
          children: children,
        },
      ],
    };
  }

  findOne(id: number) {
    return `This action returns a #${id} map`;
  }

  // update(id: number, updateMapDto: UpdateMapDto) {
  //   return `This action updates a #${id} map`;
  // }

  remove(id: number) {
    return `This action removes a #${id} map`;
  }
}
